import { api } from '../boot/axios';
import { QRLocationCategoryI, QRLocationMapI } from './type';


function url(s: string) {
  if (s==''){
    return ['/api/qrmaplocation', ''].join('/')
  }
  return ['/api/qrmaplocation', s.replace('/', ''), ''].join('/')
}

export function listqrmap() {
  return api({
    url: url(''),
    method: 'get',
  });
}

export function getLocationByQR(qr_string: string) {
  return api({
    url: url('map_location_qrcode'),
    method: 'post',
    data:{
      qr_string
    }
  });
}

export function createQRMapping(qr_string:string,stock_code:string,serial_no:string){
  return api({
    url: url('create_map_qrcode'),
    method: 'post',
    data:{
      qr_string,
      stock_code,
      serial_no
    }
  });
}

export function getQRFormatList(stock_code: string, serial_no: string) {
  return api({
    url: url('get_qr_format_list'),
    method: 'post',
    data:{
      stock_code,
      serial_no
    }
  });
}

export function deleteQrFormat(id:number) {
  return api({
    url: url(''+id),
    method: 'delete',
  });
}


export async function patchQrFormat (id:number,data:Partial<QRLocationMapI>={}){
  const res = await api({
    url: url(''+id),
    method: 'patch',
    data
  })
  return res.data as QRLocationMapI
}

export async function createQrFormat (data:Partial<QRLocationMapI>={}){
  const res = await api({
    url: url(''),
    method: 'post',
    data
  })
  return res.data as QRLocationMapI
}

export async function getQrFormat (id:number){
  const res = await api({
    url: url(''+id),
    method: 'get',
  })
  return res.data as QRLocationMapI
}

export async function getQRLocationCategory(){
  const res = await api({
    url: '/api/qrmaplocationcategory/',
    method: 'get',
  })
  return res.data as QRLocationCategoryI
}

export async function getLocationQrcode (id:number, qrcode_size: number, cews_size: number){
  const res = await api({
    url: url('get_location_qrcode'),
    method: 'post',
    data:{
      id,
      qrcode_size,
      cews_size
    }
  })
  return res.data as QRLocationMapI
}